package service.impl;

import Dao.PlayListDao;
import Dao.SongsDao;
import Dao.impl.PlayListDaoImpl;
import Dao.impl.SongsDaoImpl;
import pojo.Playlist;
import pojo.Songs;
import service.PlayListService;

import java.util.ArrayList;
import java.util.List;

public class PlayListServiceImpl implements PlayListService {
    private PlayListDao playListDao = new PlayListDaoImpl();
    private SongsDao songsDao = new SongsDaoImpl();
    @Override
    public boolean addToPlaylist(int userId, List<Integer> songIdList) {
        // 一个userId 循环插入songIdList中的所有songId
        for (Integer songId : songIdList) {
            boolean result = playListDao.addPlayList(userId, songId);
            if (!result) {
                return false;
            }
        }
        return true;
    }

    @Override
    public List<Songs> selectAllSongs() {
        // 将playlists中的所有歌曲Id查询出来，然后查询歌曲信息
        List<Playlist> playlist = playListDao.selectAllplaylist();
        List<Songs> songs = new ArrayList<>();
        // 循环遍历songIdList中的所有Id，然后查询歌曲信息
        for (Playlist plays : playlist) {
            songs.add(songsDao.selectSongById(plays.getSongId()));
        }
        return songs;
    }
}
